package org.gnyxy.mapper;

import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.gnyxy.dto.AddressDicPageQueryDTO;
import org.gnyxy.entity.AddressDic;

import java.util.List;

@Mapper
public interface AddressDicMapper {
    @Insert("insert into address_dic ( district_name,  village_name,  street_name, deleted) values " +
            "( #{districtName}, #{villageName},#{streetName},#{deleted})")
    void insert(AddressDic addressDic);

    @Select("select * from address_dic where deleted = 0 and id = #{id}")
    AddressDic getById(Long id);

    void update(AddressDic addressDic);

    Page<AddressDic> pageQuery(AddressDicPageQueryDTO addressDicPageQueryDTO);

    @Select("select distinct district_name from address_dic where deleted = 0")
    List<String> getDistrict();

    @Select("select distinct street_name from address_dic where deleted = 0 and district_name = #{districtName}")
    List<String> getStreet(String districtName);

    @Select("select distinct village_name from address_dic where deleted = 0 and district_name = #{districtName} and street_name = #{streetName}")
    List<String> getVillage(String districtName, String streetName);
}
